package com.csdn.leon.activity;


import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.csdn.leon.base.BaseActivity;
import com.csdn.leon.util.SPUtils;
import com.csdn.leon.base.R;

public class SplashActivity extends BaseActivity{

	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		ImageView imageview =new ImageView(this);
		imageview.setImageResource(R.drawable.splash_bg);
		Animation anim = AnimationUtils.loadAnimation(this, R.anim.splash_start);
		anim.setDuration(1500);
		anim.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				jumpTo();
			}
		});
		
		imageview.setAnimation(anim);
		setContentView(imageview);

	}
	
	 private void jumpTo() {
	        boolean isFirst = (boolean) SPUtils.get(this, "first_open", true);
	        Intent jumpIntent = new Intent();
	        if (!isFirst) {
	            jumpIntent.setClass(this, MainActivity.class);
	        } else {
	        	SPUtils.put(this, "first_open", false);
	            jumpIntent.setClass(this, SplashActivity.class);
	        }
	        startActivity(jumpIntent);
	        finish();
	    }
}
